<template>
  <div>
    <div class="logistics-info-header">
      <div class="logistics-info-header-left">
        <div class="logistics-status" :style="{ color }">{{ ['未发货', '已发货', '已签收', '未签收'][orderInfo.logisticsStatus] }}</div>
        <div class="logistics-company">{{ orderInfo.logisticsCompany }}</div>
        <div class="logistics-no">{{ orderInfo.logisticsNo }}</div>
      </div>
    </div>
    <ul class="logistics-info-list">
      <!-- 用 i 作为 key，缺点：当列表动态改变时，顺序可能会错乱 -->
      <!-- 但是，如果你的列表不会动态改变，其实可以用 i -->
      <li v-for="v, i of orderInfo.logisticsInfo" :key="i">
        <div class="logistics-info-list-time">{{ v.time }}</div>
        <div class="logistics-info-list-content">{{ v.content }}</div>
      </li>
    </ul>
    <!-- <button v-if="isVisibleDetailBtn">查看物流详情</button> -->
    <button v-look="orderInfo.role">查看物流详情</button>
  </div>
</template>

<script>
export default {
  name: 'LogisticsInformation',
  directives: {
    'look': {
      inserted(el, binding) {
        if (!['admin', 'zhangsan', 'lisi'].includes(binding.value)) {
          el.remove()
        }
      }
    }
  },
  props: {
    orderInfo: {
      type: Object,
      required: true
    }
  },
  computed: {

    // // 基于 orderInfo.role 得到一个 是否能看到按钮 Boolean 值
    // // isXxxx => 是否xxx
    // // xxxAble => 能干啥
    // isVisibleDetailBtn() {
    //   // if (this.orderInfo.role === 'admin' || ....)

    //   // 看数组中是否包含 实参，包含 返回 true，否则 返回 false
    //   return ['admin', 'zhangsan', 'lisi'].includes(this.orderInfo.role)
    // },
    

    // 字体颜色 只是一个 样式属性，用 :style 绑定就行
    // 只要用计算属性 基于 状态值 得到一个 颜色值 即可
    color() {
      return ['red', 'orange', 'yellow', 'skyblue'][this.orderInfo.logisticsStatus]
    }

  },
}
</script>

<style scoped>

.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}

.logistics-status {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
</style>